package com.ustb.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ustb.springboot.common.utils.R;
import com.ustb.springboot.common.utils.TokenUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ustb.springboot.dao.QuestionBlankDao;
import com.ustb.springboot.entity.QuestionBlankEntity;
import com.ustb.springboot.service.QuestionBlankService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@Service("questionBlankService")
public class QuestionBlankServiceImpl extends ServiceImpl<QuestionBlankDao, QuestionBlankEntity> implements QuestionBlankService {

    @Resource
    private QuestionBlankDao questionBlankDao;

    @Override
    public R save(HttpServletRequest request, QuestionBlankEntity questionBlank) {
        questionBlank.setUserId(TokenUtil.getId(request));
        return this.save(questionBlank) ? R.ok(20000, "创建填空题成功！") : R.error(2000, "创建失败！");
    }

    @Override
    public R delete(Map<String, Object> body) {
        QueryWrapper<QuestionBlankEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("id"));
        return questionBlankDao.delete(queryWrapper) == 1 ? R.ok(20000, "删除成功！") : R.error(2000, "删除失败！");
    }

    @Override
    public List<QuestionBlankEntity> SearchQuestionWithQuestionId(String question_id) {
        //返回一个填空题的属性等各项信息
        QueryWrapper<QuestionBlankEntity>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",question_id);
        return questionBlankDao.selectList(queryWrapper);
    }
}